
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/


#pragma once

#include "RTToolTypes.h"
#include <string>
using std::string;

//class RTScene;
class TiXmlElement;


namespace RT
{
	//forward declaration
	class RTMaterial;
	class RTCSGNode;
	class RTIPrimitive;

	/*Load a scene from a xml file*/
	class RTSceneLoader
	{
	private:
		/*xml filename*/
		string m_filename;

	public:
		/*Constructor*/
		RTSceneLoader();

		/*Load a file*/
		bool load(const string& filename);

		/*Load a model file*/
		RTIPrimitive* loadModelFile(const string& filename)const;
	private:
		/*Load the configuration node*/
		void loadConfiguration(TiXmlElement* config)const;

		/*Load the scene node*/
		void loadScene(TiXmlElement* scene)const;

		/*Load lights*/
		void loadLights(TiXmlElement* light)const;

		/*Load materials*/
		void loadMaterials(TiXmlElement* material)const;

		/*Load objects*/
		void loadObjects(TiXmlElement* object)const;
	
		/*Load the camera*/
		void loadGeometryCamera(TiXmlElement* element)const;

		/*Load a plan*/
		RTIPrimitive* loadGeometryPlan(TiXmlElement* element)const;

		/*Load a sphere*/
		RTIPrimitive* loadGeometrySphere(TiXmlElement* element)const;

		/*Load a cylinder*/
		RTIPrimitive* loadGeometryCylinder(TiXmlElement* element)const;

		/*Load a cone*/
		RTIPrimitive* loadGeometryCone(TiXmlElement* element)const;

		/*Load a torus*/
		RTIPrimitive* loadGeometryTorus(TiXmlElement* element)const;

		/*Load triangle*/
		RTIPrimitive* loadGeometryTriangle(TiXmlElement* element)const;

		/*Load a box*/
		RTIPrimitive* loadGeometryBox(TiXmlElement* element)const;

		/*Load a CSG*/
		RTIPrimitive* loadGeometryCSG(TiXmlElement* element)const;

		/*Load CSG node*/
		RTCSGNode* loadNodeCSG(TiXmlElement* element)const;

		/*Load a geometry*/
		RTIPrimitive* loadGeometryFromFile(TiXmlElement* element)const;

		/*Load a rotation*/
		void loadTransformRotation(TiXmlElement* element, RTMatrix44& out)const;

		/*Load a translation*/
		void loadTransformTranslate(TiXmlElement* element, RTMatrix44& out)const;

		/*Load a scale*/
		void loadTransformScale(TiXmlElement* element, RTMatrix44& out)const;

		/*Load a checker procedural texture*/
		void loadProcTextureChecker(TiXmlElement* element, RTMaterial* material)const;

		/*Load a wood procedural texture*/
		void loadProcTextureWood(TiXmlElement* element, RTMaterial* material)const;

		/*Load a marble procedural texture*/
		void loadProcTextureMarble(TiXmlElement* element, RTMaterial* material)const;

		/*Load a threshold procedural texture*/
		void loadProcTextureThreshold(TiXmlElement* element, RTMaterial* material)const;

		/*Load a bump map procedural texture*/
		void loadProcTextureBump(TiXmlElement* element, RTMaterial* material)const;

		/*Load a vector3*/
		void getVector3(TiXmlElement* position, RTVector3f& vector3)const;

		/*Load a vector4*/
		void getVector3(TiXmlElement* position, RTVector4f& vector4)const;

		/*Load a float*/
		F32 getFloat(TiXmlElement* element)const;
	};
}